package com.k.kpp.model;

import java.io.Serializable;
import java.util.HashMap;

/**
 * Response for http api
 * @author k
 */
public class Resp extends HashMap<String, Object> implements Serializable{
    private static final long serialVersionUID = 1L;
    private static final int SUCCESS_CODE = 0;
    private static final String SUCCESS_MSG = "success";

    @Override
    public Resp put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public static Resp error(int code, String msg) {
        return new Resp().put("code", code).put("msg", msg);
    }

    public static Resp success() {
        return new Resp().put("code", SUCCESS_CODE).put("msg", SUCCESS_MSG);
    }

    public static void main(String[] args) {
        Resp r = Resp.success().put("data","data");
        System.out.println(r);
        Resp error = Resp.error(-1,"error").put("data","no data");
        System.out.println(error);
    }
}
